<?php

/**
 * workingtime actions.
 *
 * @package    ppstool
 * @subpackage workingtime
 * @author     HS Karlsruhe
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class workingtimeActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    //$this->forward('default', 'module');
  }
  
  public function executeCalculation(sfWebRequest $request)
  {
  		 $artikelstock = $this->getUser()->getAttribute('as');
  		 $waitingstock = $this->getUser()->getAttribute('ms');
  		 $workingstock = $this->getUser()->getAttribute('workingstock');
  		 
  		 //print_r($waitingstock);
  		 echo "<br>";
  		 //print_r($artikelstock);
  		 echo "<br>";
  		 $workingstations = array();
  		 
  		 $partscomplete =array();
  		 
  		 $ruestzeiten = array(	"1" => 60,
  		 					 	"2" => 95,
  		 						"3" => 60,
  		 						"4" => 80,
  		 						"6" => 60,
  		 						"7" => 155,
  		 						"8" => 140,
  		 						"9" => 120,
  		 						"10" => 100,
  		 						"11" => 0,
  		 						"12" => 0,
  		 						"13" => 0,
  		 						"14" => 0,
  		 						"15" => 90);
  		 
  	 	//Zur Bedarfsmenge die Missingpartmenge hinzuaddieren
	 	for ($i=1; $i<60;$i++)
	 	{	 		
		 	if(isset($artikelstock[$i])==true)	
		 	{
		 		$partscomplete[$i] = $artikelstock[$i];
		 		if(isset($waitingstock[$i])==true)	
		 		{
		 			$partscomplete[$i] += $waitingstock[$i];
		 		}
		 	}	 		 			 		
	 	}
  		 //print_r($partscomplete);
  		 
	 	//Berechnung der einzelnen Kapazit�tsbedarfe
  		 $workingstations["1"] = array("zeitbedarf" => 6 * $partscomplete["49"] +
  		 								+ 6 * ($partscomplete["54"]) 
  		 								+ 6 * ($partscomplete["29"]) 
  		 								+ $ruestzeiten["1"]
  		 								+ $workingstock["1"]);
  		 								
  		 $workingstations["2"] = array("zeitbedarf" => 5 * $partscomplete["50"] +
  		 								+ 5 * ($partscomplete["55"]) 
  		 								+ 5 * ($partscomplete["30"]) 
  		 								+ $ruestzeiten["2"]
  		 								+ $workingstock["2"]);
  		 								
		 $workingstations["3"] = array("zeitbedarf" => 5 * $partscomplete["51"] +
  		 								+ 6 * ($partscomplete["56"]) 
  		 								+ 6 * ($partscomplete["31"]) 
  		 								+ $ruestzeiten["3"]
  		 								+ $workingstock["3"]);
  		 								
  		 $workingstations["4"] = array("zeitbedarf" => 6 * $partscomplete["1"] +
  		 								+ 7 * ($partscomplete["2"]) 
  		 								+ 7 * ($partscomplete["3"]) 
  		 								+ $ruestzeiten["4"]
  		 								+ $workingstock["4"]);
  		 								
  		 $workingstations["6"] = array("zeitbedarf" => 2 * $partscomplete["16"] +
  		 								+ 3 * ($partscomplete["18"]) 
  		 								+ 3 * ($partscomplete["19"])  		 								 
  		 								+ 3 * ($partscomplete["20"]) 
  		 								+ $ruestzeiten["6"]
  		 								+ $workingstock["6"]);
  		 								
  		 $workingstations["7"] = array("zeitbedarf" => 2 * $partscomplete["10"] +
  		 								+ 2 * ($partscomplete["11"]) 
  		 								+ 2 * ($partscomplete["12"])  		 								
  		 								+ 2 * ($partscomplete["13"])  		 								 
  		 								+ 2 * ($partscomplete["14"])
  		 								+ 2 * ($partscomplete["15"])
  		 								+ 2 * ($partscomplete["18"])
  		 								+ 2 * ($partscomplete["19"])
  		 								+ 2 * ($partscomplete["20"])
  		 								+ 2 * ($partscomplete["26"]) 
  		 								+ $ruestzeiten["7"]
  		 								+ $workingstock["7"]);
  		 								
  		 $workingstations["8"] = array("zeitbedarf" => 1 * $partscomplete["10"] +
  		 								+ 2 * ($partscomplete["11"]) 
  		 								+ 2 * ($partscomplete["12"])  		 								
  		 								+ 1 * ($partscomplete["13"])  		 								 
  		 								+ 2 * ($partscomplete["14"])
  		 								+ 2 * ($partscomplete["15"])
  		 								+ 3 * ($partscomplete["18"])
  		 								+ 3 * ($partscomplete["19"])
  		 								+ 3 * ($partscomplete["20"])
  		 								+ $ruestzeiten["8"]
  		 								+ $workingstock["8"]);
  		 								
  		 $workingstations["9"] = array("zeitbedarf" => 3 * $partscomplete["10"] +
  		 								+ 3 * ($partscomplete["11"]) 
  		 								+ 3 * ($partscomplete["12"])  		 								
  		 								+ 3 * ($partscomplete["13"])  		 								 
  		 								+ 3 * ($partscomplete["14"])
  		 								+ 3 * ($partscomplete["15"])
  		 								+ 2 * ($partscomplete["18"])
  		 								+ 2 * ($partscomplete["19"])
  		 								+ 2 * ($partscomplete["20"])
  		 								+ $ruestzeiten["9"]
  		 								+ $workingstock["9"]);
  		 								
  		 $workingstations["10"] = array("zeitbedarf" => 4 * $partscomplete["4"] +
  		 								+ 4 * ($partscomplete["5"]) 
  		 								+ 4 * ($partscomplete["6"])  		 								
  		 								+ 4 * ($partscomplete["7"])  		 								 
  		 								+ 4 * ($partscomplete["8"])
  		 								+ 4 * ($partscomplete["9"])
  		 								+ $ruestzeiten["10"]
  		 								+ $workingstock["10"]);
  		 								
  		 $workingstations["11"] = array("zeitbedarf" => 3 * $partscomplete["4"] +
  		 								+ 3 * ($partscomplete["5"]) 
  		 								+ 3 * ($partscomplete["6"])  		 								
  		 								+ 3 * ($partscomplete["7"])  		 								 
  		 								+ 3 * ($partscomplete["8"])
  		 								+ 3 * ($partscomplete["9"])
  		 								+ $ruestzeiten["11"]
  		 								+ $workingstock["11"]);
  		 								
  		 $workingstations["12"] = array("zeitbedarf" => 3 * $partscomplete["10"] +
  		 								+ 3 * ($partscomplete["11"]) 
  		 								+ 3 * ($partscomplete["12"])  		 								
  		 								+ 3 * ($partscomplete["13"])  		 								 
  		 								+ 3 * ($partscomplete["14"])
  		 								+ 3 * ($partscomplete["15"])
  		 								+ $ruestzeiten["12"]
  		 								+ $workingstock["12"]);
  		 								
  		 $workingstations["13"] = array("zeitbedarf" => 2 * $partscomplete["10"] +
  		 								+ 2 * ($partscomplete["11"]) 
  		 								+ 2 * ($partscomplete["12"])  		 								
  		 								+ 2 * ($partscomplete["13"])  		 								 
  		 								+ 2 * ($partscomplete["14"])
  		 								+ 2 * ($partscomplete["15"])
  		 								+ $ruestzeiten["13"]
  		 								+ $workingstock["13"]);
  		 								
  		 $workingstations["14"] = array("zeitbedarf" => 3 * $partscomplete["16"]
  		 								+ $ruestzeiten["14"]
  		 								+ $workingstock["14"]);
  		 								
  		 $workingstations["15"] = array("zeitbedarf" => 3 * $partscomplete["17"]
  		 								+ 3 * ($partscomplete["26"])
  		 								+ $ruestzeiten["15"]
  		 								+ $workingstock["15"]);
  		 								
  		 //Zeitbedarf	
  		 for($i=1;$i<=15;$i++)	
  		 {	  		 	 
  		 	 if($i == 5)
  		 	 { 
  		 	 	continue;
  		 	 } 
  		 	 //Generel + 5 %	
  		 	 $workingstations[$i]["zeitbedarf"] = round($workingstations[$i]["zeitbedarf"]*1.05,0);		
	  		 if($workingstations[$i]["zeitbedarf"] > 2400)
	  		 {
	  		 	if($workingstations[$i]["zeitbedarf"] > 3600)
	  		 	{
	  		 	  	if($workingstations[$i]["zeitbedarf"] > 4800)
		  		 	{
		  		 		if($workingstations[$i]["zeitbedarf"] > 6000)
			  		 	{
			  		 		$workingstations[$i] = array(	"zeitbedarf" => $workingstations[$i]["zeitbedarf"],
			  		 										"shift" => 3,
	  		 										        "overtime" => 0);		 		
			  		 	}
			  		 	else 
			  		 	{
			  		 		$workingstations[$i] = array(	"zeitbedarf" => $workingstations[$i]["zeitbedarf"],
			  		 										"shift" => 2,
	  		 										        "overtime" => ($workingstations[$i]["zeitbedarf"]- 4800) / 5);
			  		 	}			 		
		  		 	}
		  		 	else 
		  		 	{
		  		 		$workingstations[$i] = array(	"zeitbedarf" => $workingstations[$i]["zeitbedarf"],
		  		 										"shift" => 2,
	  		 										    "overtime" => 0);
		  		 	}		 		
	  		 	}
	  		 	else 
	  		 	{
	  		 		$workingstations[$i] = array(	"zeitbedarf" => $workingstations[$i]["zeitbedarf"],
	  		 										"shift" => 1,
	  		 										"overtime" => ($workingstations[$i]["zeitbedarf"]- 2400) / 5);
	  		 	}
	  		 }
  		 	 else 
	  		 {
	  		 	$workingstations[$i] = array(	"zeitbedarf" => $workingstations[$i]["zeitbedarf"],
	  		 									"shift" => 1,
	  		 									"overtime" => 0);
	  		 }
	  		$workingstations[$i]["overtime"]= ceil($workingstations[$i]["overtime"]);
  		 }
  		 print_r($workingstations); 
  		 $this->getUser()->setAttribute('workingtime',$workingstations); 		 
		 //$this->redirect('order/ordercalculation');	  	
  }
}
